package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.Vendor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 供应商 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-08-16
 */
@Mapper
public interface VendorMapper extends BaseMapper<Vendor> {

    /**
     * 修改供应商删除状态
     * @param vendorId
     */
    @Update("UPDATE dragon_vendor a SET a.deleted = CASE a.deleted WHEN 0 THEN 1 WHEN 1 THEN 0 END WHERE a.id = #{vendorId}")
    void changeDeleted(Integer vendorId);

    /**
     * 列表
     * @param vendorPage
     * @param wrapper
     * @return
     */
    @Select("SELECT M.* FROM( " +
            "select dv.*, dvt.name as vendorCategoryName  from dragon_vendor dv left join dragon_vendor_type dvt on dvt.id  = dv.vendor_category " +
            ")M ${ew.customSqlSegment} ")
    Page<Vendor> selectPageWrapper(Page<Vendor> vendorPage,@Param(Constants.WRAPPER) QueryWrapper<Vendor> wrapper);
}
